package com.itheima.web;

import com.itheima.service.OrderSettingService;
import com.itheima.support.Result;
import com.itheima.utils.POIUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    @PostMapping("/importData")
    public boolean importData(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        List<String[]> data = POIUtils.readExcel(multipartFile.getInputStream(),multipartFile.getOriginalFilename());
        return orderSettingService.importData(data);
    }

    @GetMapping("/selectByYearMonth/{year}/{month}")
    public Map selectByYearMonth(@PathVariable("year") int year, @PathVariable("month") int month){
        return orderSettingService.selectByYearMonth(year,month);
    }

    @GetMapping("/settingData/{day}/{num}")
    public boolean settingData(@PathVariable("day") String day,@PathVariable("num") int num){
        return orderSettingService.settingData(day,num);
    }
    @GetMapping("/deleteOrderSettingByMonth/{today}")
   public Result deleteOrderSettingByMonth(@PathVariable("today") Date today){
        return new Result(orderSettingService.deleteOrderSettingByMonth(today));
   }
}
